package com.lz.d;

/**
 * @ClassName Demo38
 * @Description 打印水仙花数
 * @Author 2214361854
 * @Date 2022/5/27 16:28
 * @Version 1.0
 */
public class Demo38 {
    /**
     * 水仙花数：是指一个三位数，其各位数字立方和等于该数字本身
     * 例如：153就是一个水仙花数，因为153 = 1³ + 5³ + 3³
     */
    public static void main(String[] args) {
        System.out.println("打印全部水仙花");
        aims();
        System.out.println("------");
        int a = 101;
        System.out.println("判断"+a+"是否水仙花："+isAim(a));
        System.out.println("四叶玫瑰数：");
        aim4();
        System.out.println("五角星数：");
        aim5();
    }

    private static boolean isAim(int a) {
        if (a <= 100 || a > 1000) {
            System.out.println("不是水仙花");
        }
        int x = a/100;
        int y = a/10%10;
        int z = a%10;
        if(a == x*x*x+y*y*y+z*z*z) {
            return true;
        }
        return false;
    }

    private static void aims() {
        for (int a = 100; a < 1000; a++) {
            int x = a/100;
            int y = a/10%10;
            int z = a%10;
            if(a == x*x*x+y*y*y+z*z*z) {
                System.out.println(a);
            }
        }
    }

    private static void aim4() {
        for (int a = 1000; a < 10000; a++) {
            int x = a/1000;
            int y = a/100%10;
            int z = a/10%10;
            int k = a%10;
            if(a == Math.pow(x,4)+Math.pow(y,4)+Math.pow(z,4)+Math.pow(k,4)) {
                System.out.println(a);
            }
        }
    }

    private static void aim5() {
        for (int a = 10000; a < 100000; a++) {
            int x = a/10000;
            int y = a/1000%10;
            int z = a/100%10;
            int k = a/10%10;
            int t = a%10;
            if(a == Math.pow(x,5)+Math.pow(y,5)+Math.pow(z,5)+Math.pow(k,5)+Math.pow(t,5)) {
                System.out.println(a);
            }
        }
    }
}
